package es.unex.meigas.ww.gui;

import org.opengis.referencing.crs.CoordinateReferenceSystem;

import com.vividsolutions.jts.geom.Envelope;

import es.unex.meigas.dataObjects.IFeature;
import es.unex.meigas.dataObjects.IVectorLayer;
import es.unex.meigas.extGIS.AbstractGISConnection;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Sector;
import gw.layers.SextanteWindLayer;
import gw.util.ProjectionUtils;
import gw.util.WorldWindUtils;

public class WWGISConnection extends AbstractGISConnection {

	WorldWindow m_WorldWindow = null;

	public WWGISConnection(WorldWindow ww) {

		m_WorldWindow = ww;

	}

	@Override
	protected void select(IVectorLayer layer, int iField) {

		//no selection in WW

	}

	@Override
	protected void setScale(IVectorLayer layer, int minScale) {

//		FLayer flayer = (FLayer) layer.getBaseDataObject();
//		flayer.getMapContext().setScaleView(minScale);

	}

	@Override
	protected void zoomTo(IVectorLayer layer , IFeature feature) {

		Envelope env = feature.getGeometry().getEnvelopeInternal();
		double p1[] = new double[2];
		double p2[] = new double[2];
		p1[0] = env.getMinX();
		p1[1] = env.getMinY();
		p2[0] = env.getMaxX();
		p2[1] = env.getMaxY();

		LatLon latLon1 = ProjectionUtils.toLatLon(p1, (CoordinateReferenceSystem)layer.getCRS());
		LatLon latLon2 = ProjectionUtils.toLatLon(p2, (CoordinateReferenceSystem)layer.getCRS());
		Sector sect = new Sector(latLon1.getLatitude(), latLon2.getLatitude(),
				latLon1.getLongitude(), latLon2.getLongitude());
		WorldWindUtils.flyTo(sect, m_WorldWindow);

	}

	@Override
	protected void clearSelection(IVectorLayer layer) {

		//no selection in WW

	}

}
